/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package org.dynamo.database.reverse.emf.metadata.impl;

import org.dynamo.database.reverse.emf.metadata.Column;
import org.dynamo.database.reverse.emf.metadata.MetadataPackage;
import org.dynamo.database.reverse.emf.metadata.Table;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.util.EcoreUtil;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Column</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link org.dynamo.database.reverse.emf.metadata.impl.ColumnImpl#getOwner <em>Owner</em>}</li>
 *   <li>{@link org.dynamo.database.reverse.emf.metadata.impl.ColumnImpl#getLength <em>Length</em>}</li>
 *   <li>{@link org.dynamo.database.reverse.emf.metadata.impl.ColumnImpl#isNullable <em>Nullable</em>}</li>
 *   <li>{@link org.dynamo.database.reverse.emf.metadata.impl.ColumnImpl#getPrecision <em>Precision</em>}</li>
 *   <li>{@link org.dynamo.database.reverse.emf.metadata.impl.ColumnImpl#isUnique <em>Unique</em>}</li>
 *   <li>{@link org.dynamo.database.reverse.emf.metadata.impl.ColumnImpl#getScale <em>Scale</em>}</li>
 *   <li>{@link org.dynamo.database.reverse.emf.metadata.impl.ColumnImpl#getSqlTypeCode <em>Sql Type Code</em>}</li>
 *   <li>{@link org.dynamo.database.reverse.emf.metadata.impl.ColumnImpl#isFK <em>FK</em>}</li>
 *   <li>{@link org.dynamo.database.reverse.emf.metadata.impl.ColumnImpl#isReferencedFK <em>Referenced FK</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class ColumnImpl extends NamedElementImpl implements Column {
	/**
	 * The default value of the '{@link #getLength() <em>Length</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLength()
	 * @generated
	 * @ordered
	 */
	protected static final int LENGTH_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getLength() <em>Length</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLength()
	 * @generated
	 * @ordered
	 */
	protected int length = LENGTH_EDEFAULT;

	/**
	 * The default value of the '{@link #isNullable() <em>Nullable</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isNullable()
	 * @generated
	 * @ordered
	 */
	protected static final boolean NULLABLE_EDEFAULT = false;

	/**
	 * The cached value of the '{@link #isNullable() <em>Nullable</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isNullable()
	 * @generated
	 * @ordered
	 */
	protected boolean nullable = NULLABLE_EDEFAULT;

	/**
	 * The default value of the '{@link #getPrecision() <em>Precision</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPrecision()
	 * @generated
	 * @ordered
	 */
	protected static final int PRECISION_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getPrecision() <em>Precision</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPrecision()
	 * @generated
	 * @ordered
	 */
	protected int precision = PRECISION_EDEFAULT;

	/**
	 * The default value of the '{@link #isUnique() <em>Unique</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isUnique()
	 * @generated
	 * @ordered
	 */
	protected static final boolean UNIQUE_EDEFAULT = false;

	/**
	 * The cached value of the '{@link #isUnique() <em>Unique</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isUnique()
	 * @generated
	 * @ordered
	 */
	protected boolean unique = UNIQUE_EDEFAULT;

	/**
	 * The default value of the '{@link #getScale() <em>Scale</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getScale()
	 * @generated
	 * @ordered
	 */
	protected static final int SCALE_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getScale() <em>Scale</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getScale()
	 * @generated
	 * @ordered
	 */
	protected int scale = SCALE_EDEFAULT;

	/**
	 * The default value of the '{@link #getSqlTypeCode() <em>Sql Type Code</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSqlTypeCode()
	 * @generated
	 * @ordered
	 */
	protected static final int SQL_TYPE_CODE_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getSqlTypeCode() <em>Sql Type Code</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSqlTypeCode()
	 * @generated
	 * @ordered
	 */
	protected int sqlTypeCode = SQL_TYPE_CODE_EDEFAULT;

	/**
	 * The default value of the '{@link #isFK() <em>FK</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isFK()
	 * @generated
	 * @ordered
	 */
	protected static final boolean FK_EDEFAULT = false;

	/**
	 * The cached value of the '{@link #isFK() <em>FK</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isFK()
	 * @generated
	 * @ordered
	 */
	protected boolean fk = FK_EDEFAULT;

	/**
	 * The default value of the '{@link #isReferencedFK() <em>Referenced FK</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isReferencedFK()
	 * @generated
	 * @ordered
	 */
	protected static final boolean REFERENCED_FK_EDEFAULT = false;

	/**
	 * The cached value of the '{@link #isReferencedFK() <em>Referenced FK</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #isReferencedFK()
	 * @generated
	 * @ordered
	 */
	protected boolean referencedFK = REFERENCED_FK_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ColumnImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return MetadataPackage.Literals.COLUMN;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Table getOwner() {
		if (eContainerFeatureID != MetadataPackage.COLUMN__OWNER) return null;
		return (Table)eContainer();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetOwner(Table newOwner, NotificationChain msgs) {
		msgs = eBasicSetContainer((InternalEObject)newOwner, MetadataPackage.COLUMN__OWNER, msgs);
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setOwner(Table newOwner) {
		if (newOwner != eInternalContainer() || (eContainerFeatureID != MetadataPackage.COLUMN__OWNER && newOwner != null)) {
			if (EcoreUtil.isAncestor(this, newOwner))
				throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
			NotificationChain msgs = null;
			if (eInternalContainer() != null)
				msgs = eBasicRemoveFromContainer(msgs);
			if (newOwner != null)
				msgs = ((InternalEObject)newOwner).eInverseAdd(this, MetadataPackage.TABLE__COLUMNS, Table.class, msgs);
			msgs = basicSetOwner(newOwner, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MetadataPackage.COLUMN__OWNER, newOwner, newOwner));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getLength() {
		return length;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLength(int newLength) {
		int oldLength = length;
		length = newLength;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MetadataPackage.COLUMN__LENGTH, oldLength, length));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isNullable() {
		return nullable;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setNullable(boolean newNullable) {
		boolean oldNullable = nullable;
		nullable = newNullable;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MetadataPackage.COLUMN__NULLABLE, oldNullable, nullable));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getPrecision() {
		return precision;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPrecision(int newPrecision) {
		int oldPrecision = precision;
		precision = newPrecision;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MetadataPackage.COLUMN__PRECISION, oldPrecision, precision));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isUnique() {
		return unique;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setUnique(boolean newUnique) {
		boolean oldUnique = unique;
		unique = newUnique;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MetadataPackage.COLUMN__UNIQUE, oldUnique, unique));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getScale() {
		return scale;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setScale(int newScale) {
		int oldScale = scale;
		scale = newScale;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MetadataPackage.COLUMN__SCALE, oldScale, scale));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getSqlTypeCode() {
		return sqlTypeCode;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setSqlTypeCode(int newSqlTypeCode) {
		int oldSqlTypeCode = sqlTypeCode;
		sqlTypeCode = newSqlTypeCode;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MetadataPackage.COLUMN__SQL_TYPE_CODE, oldSqlTypeCode, sqlTypeCode));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isFK() {
		return fk;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setFK(boolean newFK) {
		boolean oldFK = fk;
		fk = newFK;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MetadataPackage.COLUMN__FK, oldFK, fk));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean isReferencedFK() {
		return referencedFK;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setReferencedFK(boolean newReferencedFK) {
		boolean oldReferencedFK = referencedFK;
		referencedFK = newReferencedFK;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, MetadataPackage.COLUMN__REFERENCED_FK, oldReferencedFK, referencedFK));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case MetadataPackage.COLUMN__OWNER:
				if (eInternalContainer() != null)
					msgs = eBasicRemoveFromContainer(msgs);
				return basicSetOwner((Table)otherEnd, msgs);
		}
		return super.eInverseAdd(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case MetadataPackage.COLUMN__OWNER:
				return basicSetOwner(null, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
		switch (eContainerFeatureID) {
			case MetadataPackage.COLUMN__OWNER:
				return eInternalContainer().eInverseRemove(this, MetadataPackage.TABLE__COLUMNS, Table.class, msgs);
		}
		return super.eBasicRemoveFromContainerFeature(msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case MetadataPackage.COLUMN__OWNER:
				return getOwner();
			case MetadataPackage.COLUMN__LENGTH:
				return new Integer(getLength());
			case MetadataPackage.COLUMN__NULLABLE:
				return isNullable() ? Boolean.TRUE : Boolean.FALSE;
			case MetadataPackage.COLUMN__PRECISION:
				return new Integer(getPrecision());
			case MetadataPackage.COLUMN__UNIQUE:
				return isUnique() ? Boolean.TRUE : Boolean.FALSE;
			case MetadataPackage.COLUMN__SCALE:
				return new Integer(getScale());
			case MetadataPackage.COLUMN__SQL_TYPE_CODE:
				return new Integer(getSqlTypeCode());
			case MetadataPackage.COLUMN__FK:
				return isFK() ? Boolean.TRUE : Boolean.FALSE;
			case MetadataPackage.COLUMN__REFERENCED_FK:
				return isReferencedFK() ? Boolean.TRUE : Boolean.FALSE;
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case MetadataPackage.COLUMN__OWNER:
				setOwner((Table)newValue);
				return;
			case MetadataPackage.COLUMN__LENGTH:
				setLength(((Integer)newValue).intValue());
				return;
			case MetadataPackage.COLUMN__NULLABLE:
				setNullable(((Boolean)newValue).booleanValue());
				return;
			case MetadataPackage.COLUMN__PRECISION:
				setPrecision(((Integer)newValue).intValue());
				return;
			case MetadataPackage.COLUMN__UNIQUE:
				setUnique(((Boolean)newValue).booleanValue());
				return;
			case MetadataPackage.COLUMN__SCALE:
				setScale(((Integer)newValue).intValue());
				return;
			case MetadataPackage.COLUMN__SQL_TYPE_CODE:
				setSqlTypeCode(((Integer)newValue).intValue());
				return;
			case MetadataPackage.COLUMN__FK:
				setFK(((Boolean)newValue).booleanValue());
				return;
			case MetadataPackage.COLUMN__REFERENCED_FK:
				setReferencedFK(((Boolean)newValue).booleanValue());
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case MetadataPackage.COLUMN__OWNER:
				setOwner((Table)null);
				return;
			case MetadataPackage.COLUMN__LENGTH:
				setLength(LENGTH_EDEFAULT);
				return;
			case MetadataPackage.COLUMN__NULLABLE:
				setNullable(NULLABLE_EDEFAULT);
				return;
			case MetadataPackage.COLUMN__PRECISION:
				setPrecision(PRECISION_EDEFAULT);
				return;
			case MetadataPackage.COLUMN__UNIQUE:
				setUnique(UNIQUE_EDEFAULT);
				return;
			case MetadataPackage.COLUMN__SCALE:
				setScale(SCALE_EDEFAULT);
				return;
			case MetadataPackage.COLUMN__SQL_TYPE_CODE:
				setSqlTypeCode(SQL_TYPE_CODE_EDEFAULT);
				return;
			case MetadataPackage.COLUMN__FK:
				setFK(FK_EDEFAULT);
				return;
			case MetadataPackage.COLUMN__REFERENCED_FK:
				setReferencedFK(REFERENCED_FK_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case MetadataPackage.COLUMN__OWNER:
				return getOwner() != null;
			case MetadataPackage.COLUMN__LENGTH:
				return length != LENGTH_EDEFAULT;
			case MetadataPackage.COLUMN__NULLABLE:
				return nullable != NULLABLE_EDEFAULT;
			case MetadataPackage.COLUMN__PRECISION:
				return precision != PRECISION_EDEFAULT;
			case MetadataPackage.COLUMN__UNIQUE:
				return unique != UNIQUE_EDEFAULT;
			case MetadataPackage.COLUMN__SCALE:
				return scale != SCALE_EDEFAULT;
			case MetadataPackage.COLUMN__SQL_TYPE_CODE:
				return sqlTypeCode != SQL_TYPE_CODE_EDEFAULT;
			case MetadataPackage.COLUMN__FK:
				return fk != FK_EDEFAULT;
			case MetadataPackage.COLUMN__REFERENCED_FK:
				return referencedFK != REFERENCED_FK_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (length: ");
		result.append(length);
		result.append(", nullable: ");
		result.append(nullable);
		result.append(", precision: ");
		result.append(precision);
		result.append(", unique: ");
		result.append(unique);
		result.append(", scale: ");
		result.append(scale);
		result.append(", sqlTypeCode: ");
		result.append(sqlTypeCode);
		result.append(", FK: ");
		result.append(fk);
		result.append(", referencedFK: ");
		result.append(referencedFK);
		result.append(')');
		return result.toString();
	}

} //ColumnImpl
